FROM node:20-slim  as build-stage
# 设置npm镜像源（全局生效）
RUN npm config set registry https://registry.npmmirror.com \
    && yarn config set registry https://registry.npmmirror.com

WORKDIR /app
COPY . .

# 安装依赖（强制使用指定镜像源）
RUN npm install --ignore-scripts --registry=https://registry.npmmirror.com --prefer-offline --no-audit 
RUN npm run docker:postinstall
RUN npm run docker:build

# 生产阶段
FROM nginx:1.27-alpine

# 从构建阶段复制产物
COPY --from=build-stage /app/dist/spa /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
